package com.cx.controller;

import com.cx.dto.ProjectDTO;
import com.cx.dto.ProjectPageDTO;
import com.cx.dto.UserPageDTO;
import com.cx.service.ProjectService;
import com.cx.util.PageResult;
import com.cx.util.ResultUtil;
import com.cx.vo.ProjectVO;
import com.cx.vo.StatusAndCountVO;
import com.cx.vo.TaskOfProjectVO;
import com.cx.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: 晨曦
 * @Description: 项目接口
 * @DateTime: 2025/4/3 14:53
 **/
@RestController
@RequestMapping("/project")
@Slf4j
@Api(value = "项目接口")
@RequiredArgsConstructor
public class ProjectController {

    private final ProjectService projectService;

    @PostMapping("/add")
    @ApiOperation(value = "添加项目")
    public ResultUtil addProject(@RequestBody ProjectDTO projectDTO) {
        log.info("添加项目!projectDTO:{}", projectDTO);
        return projectService.add(projectDTO);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    public ResultUtil<PageResult<ProjectVO>> getUserList(ProjectPageDTO projectPageDTO) {
        {
            log.info("分页查询！projectPageDTO:{}", projectPageDTO);
            return projectService.getProjectList(projectPageDTO);
        }

    }

    @PutMapping("/updateStatusById/{id}")
    @ApiOperation(value = "根据id修改状态")
    public ResultUtil updateStatusById(@PathVariable("id") Integer id) {
        log.info("根据id修改状态！id：{}", id);
        return projectService.updateStatusById(id);
    }

    @PutMapping("/updateProjectById")
    @ApiOperation(value = "根据id修改项目")
    public ResultUtil updateProjectById(@RequestBody ProjectDTO projectDTO) {
        log.info("根据id修改项目！projectDTO：{}", projectDTO);
        return projectService.updateProjectById(projectDTO);
    }

    @GetMapping("/selectProjectById/{id}")
    @ApiOperation("根据id查询项目")
    public ResultUtil<ProjectVO> selectProjectById(@PathVariable("id") Integer id){
        log.info("根据id查询项目！id：{}",id);
        return projectService.selectProjectById(id);
    }
    @DeleteMapping("/deleteProById")
    @ApiOperation(value = "根据id删除项目")
    public ResultUtil deleteProById(@RequestParam("id") Integer id){
        log.info("根据id删除项目！id：{}",id);
        return projectService.deleteProById(id);
    }

    @GetMapping("/selectStatus")
    @ApiOperation("查询项目完成情况")
    public ResultUtil<List<StatusAndCountVO>> selectStatus(){
        log.info("查询项目完成情况");
        return projectService.selectStatus();
    }
    @GetMapping("/selectTaskOfProject")
    @ApiOperation(value = "查看所属项目")
    public ResultUtil<List<TaskOfProjectVO>> selectTaskOfProject(){
        log.info("查看所属项目");
        return projectService.selectTaskOfProject();
    }
}